package com.wlz.testMain;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @author： wlz
 * @Date 2021/1/14 9:38
 * @description： TODO  ocr 测试
 * @version: 1.0
 */
public class TestTextOcr {


    public static void main(String[] args) throws IOException {
        // 创建实例
        ITesseract instance = new Tesseract();

        // 设置识别语言
        instance.setLanguage("chi_sim");


        // 设置识别引擎

        instance.setOcrEngineMode(1);

        // 读取文件

        BufferedImage image = ImageIO.read(TestTextOcr.class.getResourceAsStream("/1.png"));
        try {
            // 识别
            String result = instance.doOCR(image);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}
